<?
include_once('common/autoload.php');
include_once("common/header.html");
include_once("common/left.html");
include("common/areaCode.inc.php");
if(empty($_SESSION['alliance'])) exit("<script>window.location='home.html'</script>");
$memberID = $_SESSION['sid'];
$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($memberID);

$ali = new Alliance($GLOBALS['le']);
$a_info = $ali->getAlliance($memberID);
// 处理利润比例
if($ratio = $a_info['dratio']){
    $ratio = explode('|', $ratio);
    $a_info['ratio_a'] = $ratio[0];
    $a_info['ratio_b'] = $ratio[1];
    $a_info['ratio_c'] = $ratio[2];
}

// 折扣模板
if($a_info['dprice_arr']!=''){
    $a_info['dprice_arr'] = unserialize($a_info['dprice_arr']);
}else{
    $a_info['dprice_arr'] = array();
}

if(!count($a_info['dprice_arr'])){
    $a_info['dprice_arr'] = array(
        array('k'=>1,'name'=>'五折','num'=>50),
        array('k'=>2,'name'=>'六折','num'=>60),
        array('k'=>3,'name'=>'七折','num'=>70),
    );
}

// 获取当前已指定的代理商
$sql="SELECT d.darea_title,d.dtime,m.dname FROM pft_distributor_agency d LEFT JOIN pft_member m ON d.inviterID=m.id WHERE fid=$memberID";
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
    $exiagent[] = $row;
}

$sql="SELECT id,dname,getPY(dname,1) as py FROM pft_member WHERE dtype<2 AND status=0 order by py";
$GLOBALS['le']->query($sql);
$select1 = '<select style="width:160px" name="city_agent[]" class="agents"><option value="0">请选择代理商</option>';
$select2 = '<select style="width:120px"><option value="0">请选择代理商</option>';
while($row=$GLOBALS['le']->fetch_assoc()){
    if(empty($row['dname'])) continue;
    $select1.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
    $select2.='<option value="'.$row['id'].'">'.$row['py'].'-'.$row['dname'].'</option>';
}
$select1.='</select>';
$select2.='</select>';

$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:15;
$txt=$_REQUEST['txt'];
$dtype=$_REQUEST['dtype'];
$ctype=$_REQUEST['com_type'];
$prov=$_REQUEST['d_province']?$_REQUEST['d_province']:0;
$city=$_REQUEST['d_city']?$_REQUEST['d_city']:0;
$disList=array();
if($txt && $txt!="请输入企业名称\分销账号\手机"){
	$tj=" and (instr(dname,'".$txt."') or instr(cname,'".$txt."') or account='".$txt."' or mobile='".$txt."')";
}
if($prov || $city || $ctype){
	$a_t=" left join pft_member_extinfo e on e.fid=m.id ";
	$a_tj.=$prov?" and province=".$prov:"";
	$a_tj.=$city?" and city=".$city:"";
	if($ctype){
		$a_tj.=" and (";
		foreach($ctype as $v){
			$a_tj.="instr(com_type,'".$v."') or ";
		}
		$a_tj=trim($a_tj,"or ").")";
	}
}
// 获取分销商
$sel1="select dname,cname,account,mobile,m.id,son_id_type,ship_type,u.dstatus,u.dprice_zk,u.tm ";
$sel2="select count(*) total ";
$sel="from pft_member_relationship r left join pft_member m on m.id=son_id left join (select memberID,dstatus,dprice_zk,tm from pft_union_member_info where fid={$_SESSION['sid']}) u ON m.id =u.memberID ".$a_t." where m.status in (0,3) ".$tj.$a_tj." and r.status=0 and parent_id=".$_SESSION['sid']." and ship_type=0";
// echo $sel1.$sel." limit ".($currentPage-1)*$pageSize.",".$pageSize;
$GLOBALS['le']->query($sel1.$sel." limit ".($currentPage-1)*$pageSize.",".$pageSize);
while($row=$GLOBALS['le']->fetch_assoc()){

	$disList[$row['id']]=$row;
}
// print_r($disList);
// print_r($disList);
include("tpl/alliance_f.html");
include("common/footer.html");?>